#ifndef VROUTE_DEFINE_H
#define VROUTE_DEFINE_H

#include <sys/types.h>
#if defined(__cplusplus)|defined(c_plusplus)
extern "C"{
#endif

#define FIXED_PATH_TYPE_ERROR		0
#define FIXED_PATH_TYPE_AUTO		1
#define	FIXED_PATH_TYPE_FIXED		2
#define FXIED_PATH_TYPE_BOARDCAST	3


#define MAX_DEVICENICK_LEN 64
#define MAX_DEVICEID_LEN 64
#define MAX_DEVICE_IMEI 16
#pragma pack(1)
struct deviceInfo{
	char showMe;
	char nickLen;
	char userNick[MAX_DEVICENICK_LEN];
	char deviceIdLen;
	char deviceId[MAX_DEVICEID_LEN];
	char deviceIMEI[MAX_DEVICE_IMEI];
	char ttl;		
};
//#endif //DEVICEINFO

//#ifndef DEVICENODE_ENDPOINT
//	#define DEVICENODE_ENDPOINT
typedef struct _NodeAddr{
	long long int serial_id;
	int half_value[2];
} NodeAddr;

typedef struct _EndPoint{
	NodeAddr* addr;
	int port;
} EndPoint;
//#endif //DEVICENODE_ENDPOINT

//base id
typedef int vroute_t;

//callbacks
/////////////////////////
///callBack function for getAport function
/////////////////////////
typedef int (*getPortCallback)(int port);

/////////////////////////
///callback function for regist port function
/////////////////////////
typedef int (*registPortCallback)(int port);

//////////////////////////////
///call when port is closing
///when return 0 the port will close, else will not
//////////////////////////////
typedef int (*portClosingCallback)(int port);


/////////////////////////
///callBack function for bind
/////////////////////////
typedef int (*bindSyncCallback)(vroute_t vid);

///////////////////////////
///callback function for accept
///////////////////////////
typedef int (*acceptSyncCallback)(vroute_t vid);

//////////////////////////////////////////////////////////////////
/// why recv and receivefrom not give an character array??
/// recv_sync and receivefrom_sync notify data avaliable only, 
/// and because of the data record start with data part protocol header,
/// so can not let user to get data directly.
/// means must call memory object method to get data
/// notice:!!
/// in order to support C, remove port memory class define, and give a integer reprent it
//////////////////////////////////////////////////////////////////
typedef int (*recvSyncCallback)(int MemId);
typedef int (*sendSyncCallback)(int result);
typedef int (*sendToSyncCallback)(int result);
typedef int (*receiveFromSyncCallback)(int MemId);

//this callback should not disposize the nodelist memory buffer, when finish release the buffer instead
typedef int (*tarcertTargetCallback)(int result, NodeAddr* nodeList, int nodeCount);

//should use struct instead the buffer, after finished the function release the buffer instead of diconstruct the instance
//devInfo may be null if failed
//if showMe = 0, then should not get value of usernick and deviceId
typedef int (*queryTargetCallback)(int result, deviceInfo* devInfo);

//if target is not null then it's the target IMEI value
typedef int (*targetReachAbleCallback)(NodeAddr* target);

//connect
typedef int (*connectCallback)(vroute_t vid);

///receive data but not block the call Thread, bot receive and receiveFrom can use it
#define RECEIVE_FLAG_NONBLOCK			0x01
///send data but not block the call Thead, both send and sendTo can use it
#define SEND_FLAG_NONBLICK				0x02
///use only for receiveFrom, when the buffer to store data full, set flush data other than drop it
#define RECEIVE_FLAG_PACKET_FLUSH		0x04
///use only for sendTo, show send data out use fixed path or seq instead of boardcast
#define SEND_FLAG_USE_FIXEDPATH			0x08
//sendTo or receiveFrom method can use a port local exist, or the port is used as other functions, this flag can make the client to regist a new port and go on send rather than return error
#define RECORD_DATA_FLAG_CREATE_PORT	0x10
#define SEND_FLAG_USE_FIXEDPAHT_FORCE	0x20

///tracert function call flag, show tracert the node address for forward, not backword
#define TRACERT_FLAG_SINGLE		0
///tracert function call flag, show tracert the node address for forward and backword
#define TRACERT_FLAG_BOTH		1

///when call setFixedPath, the count parameter must between 'MIN_FIXEDPATH_COUNT' and 'MAX_FIXEDPATH_COUNT' include them
#define MAX_FIXEDPATH_COUNT 5
#define MIN_FIXEDPATH_COUNT 2

///the maxmium value for listen function parameter count
#define MAX_LISTEN_COUNT	5

//query type
#define QUERY_DEVICE_COND_USERNICK	1
#define QUERY_DEVICE_COND_DEVICEID	2
#define QUERY_DEVICE_COND_IMEI	3
#define QUERY_DEVICE_COND_TTL	4


#if defined(__cplusplus)|defined(c_plusplus)
}
#endif 
#endif //VROUTE_DEFINE_H
